<?php
class UserModel extends Model{
    public function getRole($uid) {
        $roles = $this->alias('u')
               ->left(['user_role','r'],'r.role_id = u.role_id')
               ->where(['u.user_id=? and u.status = ?'=>[$uid,1]])
               ->select();
        return $roles;
    }
    public function getRule($user_id){
        $roles = $this->getRole($user_id);
        var_dump($roles);
        $ids = [];
        foreach ($roles as $role) {
            $ids = array_merge($ids,unserialize($role['role_rules']));
        }
        $ids = array_unique($ids);
        var_dump($ids);
        $where = [
            'rule_id' => $ids,
            'rule_status' => 1
        ];
        $rule_mode = new UserRuleModel;
        $rules = $rule_mode->field(['rule_name','rule_condition'])->where($where)->select();
        var_dump($rules);
        $result = [];
        foreach ($rules as $rule) {
            if(empty($rule['rule_condition'])){
                $result[] = strtolower($rule['rule_name']);
            }else{
                $result[] = strtolower($rule['rule_condition']);
            }
        }
        return $result;
    }
}